package com.starbucks.opencase.tool;

import com.starbucks.opencase.entity.entPetInfo;
import com.starbucks.opencase.modualr.moKV;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class toolPetInfo {
    @Autowired
    private JdbcTemplate con;
    public List<moKV> queryOptions(){
        return con.query("select `pid` as `key`,`name` as `value` from pet_info",new BeanPropertyRowMapper<>(moKV.class));
    }
    public List<entPetInfo> queryList(String name,int pageNum){
        return con.query("select * from pet_info where name like '%"+name+"%' limit ?,?",new BeanPropertyRowMapper<>(entPetInfo.class),(pageNum-1)*30,30);
    }
    public int queryAllPageNum(String name){
        int n=con.queryForObject("select count(*) from pet_info where name like '%"+name+"%'", Integer.class);
        return n/30+(n%30==0?0:1);
    }
}
